const path = require('path');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin'); // 引入提取CSS插件
const {
    CleanWebpackPlugin
} = require('clean-webpack-plugin'); // 自动清理构建目录plugin

module.exports = {
    entry: path.join(__dirname, 'index.styl'),
    output: {
        path: path.join(__dirname, 'dist')
    },
    mode: "production",
    module: {
        // 检测stylus文件
        rules: [{
            test: /\.styl$/,
            // postcss-loader配置单独分文件写出去
            use: [MiniCSSExtractPlugin.loader, 'css-loader', 'postcss-loader', 'stylus-loader']
        }]
    },
    plugins: [
        new CleanWebpackPlugin(),
        // 记得MiniCssExtractPlugin需要传入plugin
        new MiniCSSExtractPlugin({
            filename: '[name]__[contenthash:8].css'
        })
    ]
};